﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DsacAdmin.Controllers
{
    public class ImageController : Controller
    {

        [HttpPost]
        public JsonResult Index()
        {
            HttpPostedFileBase file = Request.Files["Filedata"];

            if (file != null)
            {
                String aspxUrl = Request.Path.Substring(0, Request.Path.LastIndexOf("/") + 1);

                string path = "~/file/temp/";

                string savePath = Server.MapPath(path);

                string savename = System.Guid.NewGuid().ToString();
                string originName = savename + System.IO.Path.GetExtension(file.FileName);

                //保存原图
                file.SaveAs(System.IO.Path.Combine(savePath, originName));

                //返回图片链接
                return Json(new { name = originName }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { error = "错误" }, JsonRequestBehavior.AllowGet);
            }

        }

    }
}
